package utils

import (
	"bufio"
	"io"
	"io/ioutil"
	"os"
	"shop/pkg/logger"
)

func Copy(srcFileName, targetFileName string) {
	buf, err := ioutil.ReadFile(srcFileName)
	if err != nil {
		logger.Error(err)
	}
	if err := ioutil.WriteFile(targetFileName, buf, 0666); err != nil {
		logger.Error(err)
	}
}

func BigCopy(srcFileName, targetFileName string) {
	readFile, err := os.Open(srcFileName)
	if err != nil {
		logger.Error(err)
	}
	defer readFile.Close()
	readBuf := bufio.NewReader(readFile)
	wirteFile, err := os.Create(targetFileName)
	if err != nil {
		logger.Error(err)
	}
	defer wirteFile.Close()
	writeBuf := bufio.NewWriter(wirteFile)
	count, err := io.Copy(writeBuf, readBuf)
	if err != nil {
		logger.Error(err)
		return
	}
	logger.Debug("copy file success. count:", count)

}
